package com.huike.web.controller.review;


import com.huike.clues.domain.TbActivity;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;


    /**=========================================================新增数据============================================*/
    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveData1(@PathVariable("name") String name,
                               @PathVariable("age") Integer age,
                               @PathVariable("sex") String sex){

        Review review = new Review();
        review.setName(name);
        review.setAge(age);
        review.setSex(sex);
        int rows = reviewService.insertPer1(review);
        return toAjax(rows);
    }
    /*@PostMapping("/saveData")
    public  AjaxResult addOther(@RequestBody Review review){
        int rows = reviewService.insertPer1(review);
        return toAjax(rows);
    }


    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveData2(@PathVariable String name,
                               @PathVariable Integer age,
                               @PathVariable String sex){
        Review review = new Review();
        review.setName(name);
        review.setAge(age);
        review.setSex(sex);
        return toAjax(reviewService.insertPer2(name,age,sex));
    }*/
    @PostMapping("/saveData")
    public  AjaxResult addOther(@RequestBody Review review){
        int rows = reviewService.insertPer3(review);
        return toAjax(rows);
    }


    /**=========================================================删除数据=============================================*/
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable Long[] id)
    {
        return toAjax(reviewService.deletePreByIds(id));
    }

    /**=========================================================修改数据=============================================*/

    @PutMapping("/update")
    public AjaxResult edit(@RequestBody Review review)
    {

        return toAjax(reviewService.updatePre(review));
    }
    /**=========================================================查询数据=============================================*/

    @GetMapping("/getById")
    public AjaxResult select(Integer id)
    {
        return AjaxResult.success(reviewService.selectById(id));
    }

    @GetMapping("/getDataByPage")
    public TableDataInfo selectByPage(Long page, Long pageSize){
        startPage();
        List<Review> pageInfo = reviewService.selectByPage(page,pageSize);
        return getDataTable(pageInfo);
    }


}